package com.atom.process.cnmuseum.bm.dao.process;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.atom.common.dao.AvensCommonDao;
import com.atom.common.exception.AvensNullPointerException;
import com.atom.common.remote.user.UserUtil;
import com.atom.process.cnmuseum.bm.entity.process.BmProcessDO;

@Repository
public class BmProcessDao extends AvensCommonDao<BmProcessDO> {

  public BmProcessDO findByProcessInstanceId(String processId) {
    List<BmProcessDO> list = super.findByProperty("processId", processId);
    if (list == null || list.size() == 0) {
      throw new AvensNullPointerException("ProcessDO is null where processId = " + processId);
    } else {
      return list.get(0);
    }
  }
  
  public void createPDO(UserUtil user, String processInstanceId, String biaoTi,String gcxxid) {
    BmProcessDO pdo = new BmProcessDO();
    pdo.setShenQingRen(user.getUserid());
    pdo.setShenQingRenText(user.getUsername());
    pdo.setShenQingBuMen(user.getOrgid());
    pdo.setShenQingBuMenText(user.getOrgname());
    pdo.setShenQingRiQi(new Date());
    pdo.setProcessId(processInstanceId);
    pdo.setBiaoTi(biaoTi);
    pdo.setGcxxid(gcxxid);
    super.save(pdo);
  }

}
